(function (fruit, util, global) {
    fruit.define("fruit.graphic.Topology.Scene", {
        methods: {
            init: function (inTopology, inContext) {
                this.topology = inTopology;
                this.context = inContext || this;
            },
            activate: function () {
                var topology = this.topology;
                var context = this.context;
                if (topology) {
                    var events = topology.$events;
                    util.each(events, function (event) {
                        var handler = this[event];
                        if (handler) {
                            topology.on(event, function (sender, args) {
                                handler.call(this, sender, args);
                            }, this);
                        }
                    }, this);
                }
            },
            deactivate: function () {
                var topology = this.topology;
                var context = this.context;
                if (topology) {
                    var events = topology.$events;
                    util.each(events, function (event) {
                        topology.off(event);
                    }, this);
                }
            }
        }
    });


    fruit.define("fruit.graphic.Topology.SceneManager",{
        singleton: true,
        properties:{
            scenes:{
                value:{}
            },
            currentScene:{
                value:null
            }
        },
        methods:{
            registerScene:function(name,inScene,inTopology, inContext){
                var scenes = this.scenes();
                if(inScene && inScene.prototype instanceof fruit.graphic.Topology.Scene && inTopology){
                    scenes[name] =  new inScene(inTopology, inContext);
                }else{
                    fruit.log.warn("Lack of arguments or wrong scene type");
                }
                this.scenes(scenes);
            },
            activate:function(name){
                var scenes = this.scenes();
                var currentScene = this.currentScene();

                if(currentScene){
                    currentScene.deactivate();
                }
                if(name && scenes[name]){
                    scenes[name].activate();
                }
            }
        }
    });

})(fruit, fruit.util, fruit.global);